package cn.geminis.resources.service.model;

import cn.geminis.lowcode.annotation.CrudController;
import cn.geminis.lowcode.annotation.CrudRepository;
import cn.geminis.lowcode.annotation.QueryFilter;
import cn.geminis.lowcode.annotation.QueryFilterProperty;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.util.HashSet;
import java.util.Set;

/**
 * @author puddi
 */
@Entity
@Getter
@Setter
@DynamicInsert
@DynamicUpdate
@QueryFilter
@CrudRepository
@CrudController
public class Function {

    @Id
    @Column(length = 32)
    @QueryFilterProperty(filterType = QueryFilterProperty.FilterType.In)
    private String id;

    @Column(nullable = false, length = 32)
    private String name;

    @ManyToMany(cascade = {CascadeType.MERGE})
    private Set<Function> dependenceFuncs = new HashSet<>();

    @ManyToMany(mappedBy = "functions", cascade = {CascadeType.MERGE})
    private Set<Role> roles = new HashSet<>();

}
